package com.xinbo.tuiyousuper;


import java.util.ArrayList;
import java.util.List;

import com.xinbo.tuiyousuper.model.DetailData;
import com.xinbo.tuiyousuper.utils.Constans;
import com.xinbo.widget.GridView4ScrollView;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class DetailActivity extends Activity
{
	private List<DetailData>mList = new ArrayList<DetailData>(); 
	private List<DetailData>mList2 = new ArrayList<DetailData>(); 
	private int []Images={R.drawable.detail001,R.drawable.detail002,R.drawable.detail003,R.drawable.detail004,R.drawable.detail005,R.drawable.detail006}; 
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail);
		ListView mListView = (ListView) findViewById(R.id.listView1_detail);
		initData();
		View headview1 = getLayoutInflater().inflate(R.layout.headview_detail_item, null);
		View headview2 = getLayoutInflater().inflate(R.layout.headview_detail_item2, null);
		View headview3 = getLayoutInflater().inflate(R.layout.headview_detail_item3, null);
		View headview4 = getLayoutInflater().inflate(R.layout.headview_detail_item4, null);
		View headview5 = getLayoutInflater().inflate(R.layout.headview_detail_item5, null);
		View footview1 = getLayoutInflater().inflate(R.layout.footview_detail_item, null);
		View footview2 = getLayoutInflater().inflate(R.layout.footview_detail_item2, null);
		View footview3 = getLayoutInflater().inflate(R.layout.footview_detail_item3, null);
		GridView4ScrollView mGridView4ScrollView = (GridView4ScrollView) footview3.findViewById(R.id.gridViewScrollView1);
		MyAdapter2 adapter2 = new  MyAdapter2();
		mGridView4ScrollView.setAdapter(adapter2);
		mListView.addHeaderView(headview1, null, false);
		mListView.addHeaderView(headview2, null, false);
		mListView.addHeaderView(headview3, null, false);
		mListView.addHeaderView(headview4, null, false);
		mListView.addHeaderView(headview5, null, false);
		mListView.addFooterView(footview1, null, false);
		mListView.addFooterView(footview2, null, false);
		mListView.addFooterView(footview3, null, false);
		MyAdapter adapter= new MyAdapter();
		mListView.setAdapter(adapter);
		findViewById(R.id.imageView1_detail).setOnClickListener(new OnClickListener()
		{
			
			@Override
			public void onClick(View v)
			{
				finish();
			}
		});;
	}
	private void initData()
    {
	    mList.clear();
	    mList2.clear();
	    for (int i = 0; i < Constans.DetailData.DAYS.length; i++)
        {
	    	String day = Constans.DetailData.DAYS[i];
	    	String food = Constans.DetailData.FOODS[i];
	    	String hotel = Constans.DetailData.HOTELS[i];
	    	mList.add(new DetailData(day, food, hotel));
        }
	    for (int i = 0; i < Constans.DetailData.MAINNAMES.length; i++)
        {
	    	String day = Constans.DetailData.MAINNAMES[i];
	    	String food = Constans.DetailData.SUBNAMES[i];
	    	String hotel = Constans.DetailData.PRICES[i];
	    	int image = Images[i];
	    	mList2.add(new DetailData(day, food, hotel, image));
        }
    }
	class MyAdapter2 extends BaseAdapter
	{

		@Override
        public int getCount()
        {
	        // TODO Auto-generated method stub
	        return mList2.size();
        }

		@Override
        public Object getItem(int position)
        {
	        // TODO Auto-generated method stub
	        return null;
        }

		@Override
        public long getItemId(int position)
        {
	        // TODO Auto-generated method stub
	        return 0;
        }

		@Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
			View layout = getLayoutInflater().inflate(R.layout.gridview_detail_item, null);
			TextView tvName = (TextView) layout.findViewById(R.id.tvMainName_detail);
			TextView tvSub = (TextView) layout.findViewById(R.id.tvSubName_detail);
			TextView tvPrice = (TextView) layout.findViewById(R.id.tvPrice_detail);
			ImageView mImageView = (ImageView) layout.findViewById(R.id.iv_showimages_detail);
			DetailData detailData = mList2.get(position);
			tvName.setText(detailData.getDay());
			tvSub.setText(detailData.getFood());
			tvPrice.setText(detailData.getHotel());
			mImageView.setImageResource(detailData.getImage());
	        return layout;
        }
		
	}
	class MyAdapter extends BaseAdapter
	{

		@Override
        public int getCount()
        {
	        // TODO Auto-generated method stub
	        return mList.size();
        }

		@Override
        public Object getItem(int position)
        {
	        // TODO Auto-generated method stub
	        return null;
        }

		@Override
        public long getItemId(int position)
        {
	        // TODO Auto-generated method stub
	        return 0;
        }

		@Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
			View layout = getLayoutInflater().inflate(R.layout.listview_detail_item, null);
			TextView tvDay = (TextView) layout.findViewById(R.id.tvDay_detail);
			TextView tvFood = (TextView) layout.findViewById(R.id.tvFood_detail);
			TextView tvHotel = (TextView) layout.findViewById(R.id.tvHotel_detail);
			View ishide = layout.findViewById(R.id.tv_all_detail);
			DetailData detailData = mList.get(position);
			if (position==mList.size()-1)
            {
	            ishide.setVisibility(View.GONE);
            }else
            {
            	ishide.setVisibility(View.VISIBLE);
            }
            if (!"".equals(detailData.getHotel()))
            {
            	tvHotel.setVisibility(View.VISIBLE);
	           tvHotel.setText(detailData.getHotel());
            }else {
				tvHotel.setVisibility(View.INVISIBLE);
			}	
            tvDay.setText(detailData.getDay());
            tvFood.setText(detailData.getFood());
	        return layout;
        }
		
	}
}
